#include "template.h"

#include "render.h"
#include "texture.h"
#include "list.h"
#include <string.h>
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>

typedef struct _NODE_REG
{
    const char *className;
    VIEWPROC proc;
}NODE_REG;

UFO_List g_regList;

VIEWPROC ufoTemplateGetReg(const char *className)
{
	if (g_regList && className) {
		UFO_List_Iteartor it = ufoListBegin(g_regList);
		while (it) {
			NODE_REG *node = (NODE_REG*)ufoListGetElement(it);
			if (node && strcmp(node->className, className)==0 ) {
				return node->proc;
			}
			it = ufoListIteartorForward(it);
		}
	}
	return 0;
}

int ufoTemplateAddReg(const char *className, VIEWPROC proc)
{
	if (!g_regList)
		g_regList = ufoListCreate(sizeof(NODE_REG));

	if (className && proc) {
		NODE_REG node = {className, proc};
		ufoListPushBack(g_regList, &node);
		return 1;
	}

    return 0;
}
